import { IFeidaoAiMobile } from '@dfeidao/atom-mobile/interfaces';
import get from '@dfeidao/atom-mobile/local/get';
import remove from '@dfeidao/atom-mobile/local/remove';
import set from '@dfeidao/atom-mobile/local/set';
import nodejs from '@dfeidao/atom-mobile/msg/nodejs';
// import get_param from '@dfeidao/atom-mobile/nav/get-param';
import render from '@dfeidao/atom-mobile/render/render';

export default async function a007(fd: IFeidaoAiMobile) {

	const productid = get(fd, 'productids');
	const class_id = get(fd, 'class_id');// 班级编号
	const class_name = get(fd, 'class_name');// 班级名称
	const grade = get(fd, 'grade');// 年级名称
	let student_name = '';// 学生姓名
	const sn = get(fd, 'student_name') as string;// 获取学生姓名
	// console.log('sn', sn);
	if (sn) {// 判断是否获取学生姓名
		student_name = sn;// 将获取的学生姓名赋值给条件
		// remove(fd, 'student_name');// 删除存储值
	}
	let page_no = 1;// 默认页码值
	const pn = get(fd, 'page_no') as number;// 获取页码
	if (pn) {// 判断是否获取页码
		page_no = pn;// 将获取的页码赋值给条件
	}
	remove(fd, 'page_no');// 删除存储值
	const query = {// 条件
		productid,
		student_name,
		class_id,
		page_no
	};
	set(fd, 'query', query);
	// debugger;

	// console.log('--------- 上传中 ---------', query);
	// a002(fd, student_name);

	// const query = get(fd, 'query') as {
	// 	student_name: string,
	// 	class_id: string// 班级编号
	// };
	// const sn = get(fd, 'student_name') as string;
	// if (sn) {
	// 	query.student_name = sn;
	// }
	const d = await nodejs<Array<{}>>('app-review-student/s001',
		query
	);// 调用服务
	const d1 = await nodejs<Array<{}>>('app-review-student/s001',
		query
	);// 调用服务
	const cd = d1.length;
	if (cd === 0) {
		remove(fd, 'student_name');// 删除存储的值
	}
	const ys = Math.ceil(cd / 20);

	// console.log('----------查询数据----------', d, 'ys', ys);
	const new_len = d.length;
	set(fd, 'new_len', new_len);// 存储值
	// const c = '0';
	render(fd, { d, page_no, new_len, class_name, grade, ys });// 渲染数据
}
